package com.zxc.pricing.decorator;

// FullReductionDecorator.java
import com.zxc.enums.Fruit;
import com.zxc.pricing.PriceCalculator;

import java.util.Map;
/**
 * 满减优惠装饰器
 */
public class FullReductionDecorator implements PriceCalculator {
    private final PriceCalculator calculator;
    private final double threshold;
    private final double reduction;

    public FullReductionDecorator(PriceCalculator calculator, double threshold, double reduction) {
        this.calculator = calculator;
        this.threshold = threshold;
        this.reduction = reduction;
    }

    @Override
    public double calculateTotal(Map<Fruit, Integer> fruits) {
        double total = calculator.calculateTotal(fruits);

        // 如果满足满减条件，则减去相应金额
        if (total >= threshold) {
            total -= reduction;
        }

        return total;
    }
}
